﻿USE [Pixxler]
GO
/****** Object:  Table [dbo].[pxl_Benutzer]    Script Date: 03/23/2013 12:08:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pxl_Benutzer](
	[IDBenutzer] [uniqueidentifier] NOT NULL,
	[Benutzername] [nvarchar](150) NOT NULL,
	[Passwort] [nvarchar](max) NOT NULL,
	[EmailAdresse] [nvarchar](200) NOT NULL,
 CONSTRAINT [PK_pxl_Benutzer] PRIMARY KEY CLUSTERED 
(
	[IDBenutzer] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY],
 CONSTRAINT [IX_pxl_Benutzer] UNIQUE NONCLUSTERED 
(
	[EmailAdresse] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Emailadresse muss eindeutig sein' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'pxl_Benutzer', @level2type=N'CONSTRAINT',@level2name=N'IX_pxl_Benutzer'
GO
/****** Object:  Table [dbo].[pxl_Album]    Script Date: 03/23/2013 12:08:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pxl_Album](
	[IDAlbum] [uniqueidentifier] NOT NULL,
	[Titel] [nvarchar](max) NOT NULL,
	[ErstelltAm] [datetime2](7) NOT NULL,
	[BesitzerBenutzerID] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_pxl_Album] PRIMARY KEY CLUSTERED 
(
	[IDAlbum] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pxl_Bilder]    Script Date: 03/23/2013 12:08:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pxl_Bilder](
	[IDBild] [uniqueidentifier] NOT NULL,
	[Bilddaten] [image] NOT NULL,
	[Titel] [nvarchar](250) NULL,
	[Beschreibung] [nvarchar](max) NULL,
	[AlbumID] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_pxl_Bilder] PRIMARY KEY CLUSTERED 
(
	[IDBild] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pxl_BenutzerAlben]    Script Date: 03/23/2013 12:08:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pxl_BenutzerAlben](
	[BenutzerID] [uniqueidentifier] NOT NULL,
	[AlbumID] [uniqueidentifier] NOT NULL,
	[CanView] [bit] NOT NULL,
	[CanAdd] [bit] NOT NULL,
	[CanDelete] [bit] NOT NULL,
 CONSTRAINT [PK_pxl_BenutzerAlben] PRIMARY KEY CLUSTERED 
(
	[BenutzerID] ASC,
	[AlbumID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Default [DF_pxl_BenutzerAlben_CanView]    Script Date: 03/23/2013 12:08:09 ******/
ALTER TABLE [dbo].[pxl_BenutzerAlben] ADD  CONSTRAINT [DF_pxl_BenutzerAlben_CanView]  DEFAULT ((0)) FOR [CanView]
GO
/****** Object:  Default [DF_pxl_BenutzerAlben_CanAdd]    Script Date: 03/23/2013 12:08:09 ******/
ALTER TABLE [dbo].[pxl_BenutzerAlben] ADD  CONSTRAINT [DF_pxl_BenutzerAlben_CanAdd]  DEFAULT ((0)) FOR [CanAdd]
GO
/****** Object:  Default [DF_pxl_BenutzerAlben_CanDelete]    Script Date: 03/23/2013 12:08:09 ******/
ALTER TABLE [dbo].[pxl_BenutzerAlben] ADD  CONSTRAINT [DF_pxl_BenutzerAlben_CanDelete]  DEFAULT ((0)) FOR [CanDelete]
GO
/****** Object:  ForeignKey [FK_pxl_Album_pxl_Benutzer]    Script Date: 03/23/2013 12:08:09 ******/
ALTER TABLE [dbo].[pxl_Album]  WITH CHECK ADD  CONSTRAINT [FK_pxl_Album_pxl_Benutzer] FOREIGN KEY([BesitzerBenutzerID])
REFERENCES [dbo].[pxl_Benutzer] ([IDBenutzer])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[pxl_Album] CHECK CONSTRAINT [FK_pxl_Album_pxl_Benutzer]
GO
/****** Object:  ForeignKey [FK_pxl_BenutzerAlben_pxl_Album]    Script Date: 03/23/2013 12:08:09 ******/
ALTER TABLE [dbo].[pxl_BenutzerAlben]  WITH CHECK ADD  CONSTRAINT [FK_pxl_BenutzerAlben_pxl_Album] FOREIGN KEY([AlbumID])
REFERENCES [dbo].[pxl_Album] ([IDAlbum])
GO
ALTER TABLE [dbo].[pxl_BenutzerAlben] CHECK CONSTRAINT [FK_pxl_BenutzerAlben_pxl_Album]
GO
/****** Object:  ForeignKey [FK_pxl_BenutzerAlben_pxl_Benutzer]    Script Date: 03/23/2013 12:08:09 ******/
ALTER TABLE [dbo].[pxl_BenutzerAlben]  WITH CHECK ADD  CONSTRAINT [FK_pxl_BenutzerAlben_pxl_Benutzer] FOREIGN KEY([BenutzerID])
REFERENCES [dbo].[pxl_Benutzer] ([IDBenutzer])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[pxl_BenutzerAlben] CHECK CONSTRAINT [FK_pxl_BenutzerAlben_pxl_Benutzer]
GO
/****** Object:  ForeignKey [FK_pxl_Bilder_pxl_Album]    Script Date: 03/23/2013 12:08:09 ******/
ALTER TABLE [dbo].[pxl_Bilder]  WITH CHECK ADD  CONSTRAINT [FK_pxl_Bilder_pxl_Album] FOREIGN KEY([AlbumID])
REFERENCES [dbo].[pxl_Album] ([IDAlbum])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[pxl_Bilder] CHECK CONSTRAINT [FK_pxl_Bilder_pxl_Album]
GO
